<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.commons.Constants,
                 com.scalar.chiptrack.operations.process.forms.BomPartEntryForm,
                 java.util.Enumeration,
                 com.scalar.chiptrack.commons.SessionKeys"%>
 <%--
  Created by IntelliJ IDEA.
  User: Murali Krishna Yengala
  Date: May 12, 2005
  Time: 10:25:54 AM
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>

<chiptrack:checkLogon sourcePage="/finishedGoodsCreateNew.do?action=new" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
    <script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
    <script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
    <SCRIPT language="JavaScript">
    var errIdx;
    var chiptracErrors;
    var chiptracInfo;

    function init()
    {
        errIdx = document.getElementById("errors");
        chiptracErrors = document.getElementById("chiptracErrors");
        chiptracInfo = document.getElementById("chiptracInfo");
    }

    function getFgiParts()
    {
        var baseProductId = document.finishedGoodsForm.baseProductId.value;
        if( baseProductId == 0 || baseProductId == -1 )
        {
            chiptracErrors.innerHTML = '';
            chiptracInfo.innerHTML = '';
            errIdx.innerHTML = "<li> Please select a Base product";
            return;
        }
        document.finishedGoodsForm.action = document.finishedGoodsForm.action+"?action=new";
        document.finishedGoodsForm.submit();
    }
    function createNewFinishedGoods()
    {
        var baseProductId = document.finishedGoodsForm.baseProductId;
        var baseProductIdVal = baseProductId.value;
        if( baseProductIdVal == 0 || baseProductIdVal == -1)
        {
            chiptracErrors.innerHTML = '';
            chiptracInfo.innerHTML = '';
            errIdx.innerHTML = "<li> Please select a Base product";
            return false;
        }
        document.finishedGoodsForm.baseProductNo.value = baseProductId.options[baseProductId.selectedIndex].text;
        /*var customerId = document.finishedGoodsForm.customerId;
        var customerIdVal = customerId.value;
        if( customerIdVal == 0 || customerIdVal == -1 )
        {
            chiptracErrors.innerHTML = '';
            chiptracInfo.innerHTML = '';
            errIdx.innerHTML = "<li> Please select a Customer";
            return false;
        }
        document.finishedGoodsForm.customerName.value = customerId.options[customerId.selectedIndex].text;
        */
        var customerIds = document.finishedGoodsForm.customerIds;
        if ( customerIds && customerIds.value == "" )
        {
            chiptracErrors.innerHTML = '';
            chiptracInfo.innerHTML = '';
            errIdx.innerHTML = "<li> Please select a Customer";
            return false;
        }

        var fgiProcessStepIds = document.finishedGoodsForm.fgiProcessStepIds;
        if( fgiProcessStepIds )
        {
            if( fgiProcessStepIds.value == "")
            {
                chiptracErrors.innerHTML = '';
                chiptracInfo.innerHTML = '';
                errIdx.innerHTML = "<li> Please select a FGI Part Number";
                return false;
            }
        }
        else
        {
            chiptracErrors.innerHTML = '';
            chiptracInfo.innerHTML = '';
            errIdx.innerHTML = "<li> Selected Base product doesn't have any FGI parts, Please select a different Base product";
            return false;
        }
        document.finishedGoodsForm.action = "<%=chipTracContext%>/finishedGoodsEntry.do?action=newEntry";
        document.finishedGoodsForm.submit();
    }

    function reset()
    {
        document.finishedGoodsForm.reset();
    }
    </script>

<html>
    <HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
        <META http-equiv=Content-Type content="text/html; charset=windows-1252">
        <LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
    </HEAD>
    <BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0" onLoad="init()">
    <!-- Top Header Start-->
    <%@ include file="/jsp/includes/header.jsp" %>
    <!-- Top Header End-->
    <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
      <TBODY >
      <TR>
        <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

        <!-- Side Navigation start -->
        <%@ include file="/jsp/operations/product_menu.jsp" %></TD>
        <!-- end of the side navigations -->

        <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">

        <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
        <BR>
        <!-- from here your body starts -->
        <html:form action="/finishedGoodsCreateNew" name="finishedGoodsForm" type="com.scalar.chiptrack.operations.finishedGoods.forms.FinishedGoodsForm">
            <TABLE width='95%' align=right cellpadding='3' cellspacing='2' border='0' bordercolor='black'>
                <%--todo change the following heading if necessary--%>
                <TR><Td colspan='4' class="NArialW" align=center>Create New Finished Goods</td></tr>
                <tr><td colspan='4' align="left" class='NArialL'><FONT id="errors" color='FF0000'></font>&nbsp;</td></tr>
                <TR><TD colspan='4' id='chiptracErrors'><chiptrack:errors styleClass="NArialL"/></TD></TR>
                <TR><TD colspan='4' id='chiptracInfo'><chiptrack:info styleClass="NArialL"/></TD></tr>
                <TR>
                    <TD class='NArialL' width='25%'> Select Base Product :</TD>
                    <TD class="NArialL" width='25%'>
                        <html:select property="baseProductId" name="finishedGoodsForm" styleClass="txfield"  onchange="getFgiParts()" >
                        <html:option value="-1">Select Base Product</html:option>
                        <html:option value="0">------------------</html:option>
                        <html:options collection="baseProductsList" property="value" labelProperty="label"/>
                        </html:select>
                        <input type="hidden" name="baseProductNo" value="">
                    </TD>
                    <TD class='NArialL'> Select Customer :</TD>
                    <TD class="NArialL">
                        <html:select property="customerIds" name="finishedGoodsForm" styleClass="txfield" multiple="true" size="6">
                        <html:options collection="customersList" property="value" labelProperty="label"/>
                        </html:select>
                        <input type="hidden" name="customerName" value="">
                    </TD>
                </TR>
                <TR>
                        <TD class='NArialL'  width='25%'>
                        <logic:present name="fgiProductsList">
                            Select FGI Part Number :
                        </logic:present>
                        </TD>
                        <TD class="NArialL"  width='25%' colspan='3'>
                        <logic:present name="fgiProductsList">
                            <html:select property="fgiProcessStepIds" name="finishedGoodsForm" styleClass="txfield"  multiple="true" size="6">
                            <html:options collection="fgiProductsList" property="value" labelProperty="label"/>
                            </html:select>
                        </logic:present>
                        </TD>
                        <input type="hidden" name="fgiProductNo" value="">
                </TR>
                
                <TR><TD colspan='4'>
                    <IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='20'>
                </TD></TR>
                 <br>
<%--
                 <tr>
                    <td colspan="4"><font class="NArialL">Please <a styleClass="leftsection" href="javascript:createNewFinishedGoods()" onmouseover="window.status='Click here to create a new Finished Good';return true" onmouseout="window.status='';return true">
                    Click here</a>&nbsp;to Add Finished Goods
                    </font></td>
                 </tr>
--%>
                    <TR>
                        <TD colspan='4' align=center>
                          <input type=image border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" onmouseover="window.status='Click here to Create Finished Goods';return true" onclick="javascript:return createNewFinishedGoods()" onmouseout="window.status='';return true" title="Click here to Create Finished Goods">
                          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                          <a href="javascript:reset()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"  onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset" ></a>
                        </TD>
                    </TR>
                 </TABLE>
                 </TD></TR>
                <TR><TD colspan='4'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                </TABLE>
            </table>
        </html:form>
        <!-- till here -->
        <BR><BR><BR></TD>
        <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
        </TR>
        </TABLE>
        <!-- Footer starts here -->
        <%@ include file="/jsp/includes/footer.jsp" %>
        <!-- footer end here -->
    </body>
</html>